﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <style>
        body {
            background-color: #ececed !important;
        }
          .scroll-content {
            display: flex;
            flex-direction: column;
            align-items: stretch;
        }

        .user-block {
            background-color: #fff;
            border-radius: 3px;
            margin-bottom: 20px;
        }

        .user-info-wrapper {
            display: flex;
        }
        .check-result {
            display: block;
            min-height: 100px;
            line-height: 100px;
            vertical-align: middle;
            text-align: center;
        }
        .avator {
            flex-basis: 29.71137521222411%;
            text-align: right;
            margin-right: 4.584040747028862%;
            margin-top: 4.584040747028862%;
        }

            .avator img {
                margin-left: 10px;
                max-width: 90%;
            }

        .user-info {
            flex-grow: 1;
        }
    </style>
</head>
<body>
    <div class="user-block">
        <div class="user-info-wrapper">
            <div class="avator">
                <img id="imgId" src="images/user-icon.png">
            </div>
            <div class="user-info">
                <h3><label id="lblTitleName"></label></h3>
                <p>
                    <span>卡號:<label id="lblCardNO"></label></span>&nbsp;&nbsp;
                    <span>編號:<label id="lblNO"></label></span>
                </p>
                <p>
                    <span>姓名:<label id="lblName"></label></span>&nbsp;&nbsp;
                    <span>有效期:<label id="lblExpiryDate"></label></span>
                </p>
                <p>
                    <span>注冊工種:<label id="lblWorkerType"></label></span>
                </p>
            </div>
        </div>

    </div>
    <div class="user-block">
        <div class="check-result">
            <h3><label id="result">等待生物識別驗證……</label></h3>
        </div>
    </div>
        <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        (function ($) {
            $.getUrlParam = function (name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
        })(jQuery);
        var isOK = 0;
        $(function () {

            var testHost = "http://47.90.73.137:8089/";
            var testCard = "CWR16000108";
            var host = $.getUrlParam('host');
            var cardNo = $.getUrlParam('cwrNo');
            isOK = $.getUrlParam('isOK');
            //var faceResult = $.getUrlParam('faceResult');
            //var gps = $.getUrlParam('gps');
            //var dutyStatus = $.getUrlParam('dutyStatus');
            getWorkerPhoto(host, cardNo);
            //postResult(testHost, testCard, 0, 0, "320.4,432.4", 0);
        });
        function postResult(host, cwrNumber, dutyStatus, faceResult, gps,locationCheck) {
            var datetime = getNowFormatDate();
            var URL = host + "/iDuty.ashx";

            var json = { "ActionType": "newdutylog", "ClientVersion": "1.0", "Data": "{\"UserGUID\":null,\"CWDNumber\":\"" + cwrNumber + "\",\"DutyStatus\":\"" + dutyStatus + "\",\"CardCheck\":\"1\",\"FaceCheck\":\"" + faceResult + "\",\"Coordinate\":\"" + gps + "\",\"DutyTime\":\"" + datetime + "\",\"ContractID\":\"1413\",\"LocationCheck\":\"" + locationCheck + "\"}" };
            if (dutyStatus == 3) {
                json = { "ActionType": "newdutylog", "ClientVersion": "1.0", "Data": "{\"UserGUID\":null,\"CWDNumber\":\"" + cwrNumber + "\",\"DutyStatus\":null,\"CardCheck\":\"1\",\"FaceCheck\":\"" + faceResult + "\",\"Coordinate\":\"" + gps + "\",\"DutyTime\":\"" + datetime + "\",\"ContractID\":\"1413\",\"LocationCheck\":\"" + locationCheck + "\"}" };
            }
            $("#result").text("正在提交数据……");
            $.post(URL, { bgdata: JSON.stringify(json) }, function (result) {
                console.log(result);
                result = JSON.parse(result);
                $("#result").text(result.Result);

                window.androidShare.jsMethod("F");

            });
        }

        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                    + " " + date.getHours() + seperator2 + date.getMinutes()
                    + seperator2 + date.getSeconds();
            return currentdate;
        }

        function getWorkerPhoto(apiHost, cardNo) {
            var URL = apiHost + "iGetData.ashx";
            var data = { "ActionType": "getallworker", "ClientVersion": "1.0", "Data": "" };

            $.post(URL, { bgdata: JSON.stringify(data) }, function (result) {
                result = JSON.parse(result);

                if (result.ActionStatus === "1") {

                    var details = JSON.parse(result.Result);
                    var worker = get(details, "CWRNo", cardNo);
                    if (worker.length > 0) {
                        var imgurl = apiHost + worker[0].Photo;
                        $("#lblTitleName").text(worker[0].CName);
                        $("#lblCardNO").text(cardNo);
                        $("#lblNO").text(worker[0].RowID);
                        $("#lblName").text(worker[0].CName);
                        $("#lblExpiryDate").text(worker[0].CardExpiryDate);
                        $("#imgId").attr('src', imgurl);
                        getTrade(URL, worker[0].PractisingTrade);
                        //window.cicode.js4java(imgurl);
                        if (isOK == 1 || isOK == "1") {
                            window.androidShare.jsMethod(imgurl);
                        }
                        
                    }
                }
            });

        }

        function getTrade(URL, practisingTrade) {
            var data = { "ActionType": "gettrade", "ClientVersion": "1.0", "Data": "{\"UserDataGUID\":null,\"ContractDataGUID\":null,\"UserDataCnName\":null,\"UserDataEnName\":null,\"UserDataCWRNo\":null,\"UserDataCardSerialNumber\":null,\"UserDataGreenCardNumber\":null,\"UserDataGreenCardExpiryDate\":null,\"UserDataRegistrationNumber\":null,\"UserDataRegistrationDate\":null,\"UserDataRegistrationExpiryDate\":null,\"UserDataTel\":null,\"UserDataEmail\":null,\"UserDataPhoto\":null,\"UserDataRole\":null,\"UserDataModifiedDate\":null,\"UserDataRemoveDate\":null,\"UserDataTractisingTrade\":null,\"UserDataBiometriTemplateIdentifier\":null,\"UserDataTechnologyType\":null,\"UserDataTimestamp\":null,\"ContractDataID\":null,\"StartDate\":null,\"EndDate\":null,\"Position\":null}" };

            $.post(URL, { bgdata: JSON.stringify(data) }, function (result) {
                result = JSON.parse(result);
                if (result.ActionStatus === "1") {
                    var details = JSON.parse(result.Result);
                    var worker = get(details, "TradeData_Code", practisingTrade);
                    if (worker.length > 0) {
                        var trade = worker[0].TradeData_NameCHi;
                        $("#lblWorkerType").text(trade);
                    }
                }
            });
        }

        function get(arrPerson, objPropery, objValue) {
            return $.grep(arrPerson, function (cur, i) {
                return cur[objPropery] == objValue;
            });
        }
    </script>
</body>
</html>
